<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php include('menu.php'); ?>
</head>
<body>
<?php
include("../connect/connect.php");

//ลบข้อมูล
if($_GET["action"]==del) {

	$Query = "DELETE FROM stock_bar WHERE stock_bar_id = '".$_GET["id"]."' ";
	$objQuery = mysql_query($Query);
	if(!$objQuery)
	{
		echo "Error Delete [".mysql_error()."]";
	}
}
//ค้นหาสินค้า
if($_POST["code_search"] != "" OR $_POST["name_search"] != "" OR $_POST["category_search"] != "" OR $_POST["cost_search"] != "" OR $_POST["price_search"] != "") {
	
		$Query = "SELECT product.prod_name as prod_name,stock_bar.stock_bar_id as stock_bar_id,stock_bar.stock_bar_par as stock_bar_par FROM product,stock_bar WHERE product.prod_id = stock_bar.prod_id ";

	if($_POST["name_search"] != "") {
		$Query .= "AND product.prod_name LIKE '%".$_POST["name_search"]."%' ";
	}

	
} else {
	$Query = "SELECT product.prod_name as prod_name,stock_bar.stock_bar_id as stock_bar_id,stock_bar.stock_bar_par as stock_bar_par FROM product,stock_bar WHERE product.prod_id = stock_bar.prod_id ORDER BY product.prod_name";
}
$objQuery = mysql_query($Query) or die ("Error Query [".$Query."]");
?>
<div class="box">
  <div class="left"></div>
  <div class="right"></div>
    <div class="heading"><h1>จัดการรายการในสต็อกบาร์</h1></div>
  <div class="content">
  <table class="list">
        <thead>
          <tr>
            <td width="1" style="text-align: center;"><span class="center">ลำดับ</span></td>
            <td class="center">ชื่อสินค้า</td>
            <td class="center">Par</td>
            <td class="center">จัดการรายการ</td>
          </tr>
        </thead>
        <tbody>
		<form action="<?php $_SERVER["PHP_SELF"];?>" name="formsearch" method="post" id="formsearch">
          <tr class="filter">
            <td>&nbsp;</td>
            <td align="center"><input name="name_search" type="text" id="name_search" style="text-align: center;" onkeydown="if(event.keyCode==13){formsearch.submit();}" /></td>
            <td>&nbsp;</td>
            <td align="center"><a onclick="formsearch.submit();" class="button"><span>ค้นหา</span></a></td>
          </tr>
		</form>
<?php
	$num = 0;
	while($row = mysql_fetch_array($objQuery))
		{
			$num++;
?>
          <tr>
            <td style="text-align: center;"><?php echo $num;?></td>
            <td class="left" style="padding-left:20px"><?php echo $row["prod_name"];?></td>
            <td class="right" style="padding-right:20px"><?php echo $row["stock_bar_par"];?></td>
            <td class="center">[ <a href="stock_bar_edit.php?id=<?php echo $row["stock_bar_id"];?>">แก้ไข</a> ] [ <a href="JavaScript:if(confirm('คุณต้องการยืนยันการลบข้อมูล ใช่หรือไม่?')==true){window.location='<?php echo $_SERVER["PHP_SELF"];?>?action=del&id=<?php echo $row["stock_bar_id"];?>';}">ลบ</a> ]</td>
          </tr>
<?php
		} 
?>
        </tbody>
      </table>
  </div>
</div>

</body>
<? mysql_close(); ?>
</html>
